package cn.ljy.mes.service.impl;

import cn.ljy.authority.service.impl.IBaseService;
import cn.ljy.common.utils.page.Pagination;
import cn.ljy.common.utils.password.SHA;
import cn.ljy.mes.dao.mapper.ShopCustomerMapper;
import cn.ljy.mes.model.ShopCustomer;
import cn.ljy.mes.model.query.ShopCustomerQuery;
import cn.ljy.mes.service.ShopCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IShopCustomerService extends IBaseService<ShopCustomer, ShopCustomerQuery> implements ShopCustomerService {

    @Autowired
    private ShopCustomerMapper mapper;
    @Override
    protected void enrichEntityFields(ShopCustomer shopCustomer){
        if(shopCustomer!=null){

        }
    }

    @Override
    protected void beforeSave(ShopCustomer shopCustomer) {
        //设置初始密码为123456
        shopCustomer.setPassword(SHA.getResult("123456"));
    }

    @Override
    public Pagination queryByUserNameWithExactMatchFirst(String username) {
        Pagination pagination;
        //这里实际上不需要分页业务，但是为了配合前端封装好的组件，因此都按照分页方式返回。
        List<ShopCustomer> customers=mapper.findByUserNameWithExactMatchFirst(username);
        pagination = new Pagination(1, 10,customers.size());
        //为当前页的数据集赋值
        pagination.setData(customers);
        return pagination;
    }
}
